package com.csoa.community.activity;

import java.util.ArrayList;

import android.content.Intent;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.collect.community.R;
import com.csoa.community.adapter.ViewPagerAdapter;

public class FormActivity extends BaseActivity  {

	private ViewPager mViewPager;
	private ArrayList<View> mViewList;
	private ViewPagerAdapter mAdapter;
	private View mViewPlantForm;
	private View mViewAnimalForm;

	private Button mbtnZWForm;
	private Button mbtnDSSWForm;
	private Button mbtnDWForm;
	private Button mbtnWSWForm;
	private Button mbtnHYSWForm;
	public Button[] buttons = null;

	@Override
	public void initUI() {
		setContentView(R.layout.form);
		hiddenNar(R.id.nav_data_write);

		mbtnZWForm = (Button) this.findViewById(R.id.btnZWForm);
		mbtnDSSWForm = (Button) this.findViewById(R.id.btnDSSWForm);
		mbtnDWForm = (Button) this.findViewById(R.id.btnDWForm);
		mbtnWSWForm = (Button) this.findViewById(R.id.btnWSWForm);
		mbtnHYSWForm = (Button) this.findViewById(R.id.btnHYSWForm);
		buttons = new Button[] { mbtnZWForm, mbtnDSSWForm, mbtnDWForm,
				mbtnWSWForm, mbtnHYSWForm };
		mViewPager = (ViewPager) findViewById(R.id.viewPager);

		mViewList = new ArrayList<View>();
		mViewPlantForm = getLayoutInflater().inflate(R.layout.plant_form, null);
		mViewList.add(mViewPlantForm);
		mViewAnimalForm = getLayoutInflater().inflate(R.layout.animal_form,
				null);
		mViewList.add(mViewAnimalForm);
		mViewAnimalForm = getLayoutInflater().inflate(R.layout.animal_form,
				null);
		mViewList.add(mViewAnimalForm);
		mViewAnimalForm = getLayoutInflater().inflate(R.layout.animal_form,
				null);
		mViewList.add(mViewAnimalForm);
		mViewAnimalForm = getLayoutInflater().inflate(R.layout.animal_form,
				null);
		mViewList.add(mViewAnimalForm);
		mViewAnimalForm = getLayoutInflater().inflate(R.layout.animal_form,
				null);
		mViewList.add(mViewAnimalForm);

		mAdapter = new ViewPagerAdapter(getApplicationContext(), mViewList);
		mViewPager.setAdapter(mAdapter);

		mViewPager.setCurrentItem(0);

		mViewPager
				.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

					public void onPageSelected(int arg0) {
						buttons[arg0].setVisibility(View.VISIBLE);
						for (int i = 0; i < buttons.length; i++) {
							if (i == arg0) {
								buttons[i]
										.setBackgroundResource(R.drawable.btn_bottom_pressed);
								buttons[i]
										.setTextColor(_activity
												.getResources()
												.getColor(
														R.color.bottom_btn_color_pressed));
							} else {
								buttons[i]
										.setBackgroundResource(R.drawable.btn_bottom_normal);
								buttons[i]
										.setTextColor(_activity
												.getResources()
												.getColor(
														R.color.bottom_btn_color_normal));
							}

						}
					}

					public void onPageScrolled(int arg0, float arg1, int arg2) {

					}

					public void onPageScrollStateChanged(int arg0) {

					}
				});

		mViewPlantForm.findViewById(R.id.tvYFFaForm).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						Intent intent = new Intent(FormActivity.this,
								YFInfoTableActivity.class);
						startActivity(intent);
					}
				});

		mViewPlantForm.findViewById(R.id.tvMLMain).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						Intent intent = new Intent(FormActivity.this,
								WZMLInfoTableActivity.class);
						startActivity(intent);
					}
				});
		

	}

	@Override
	public void initData() {
		mbtnZWForm.setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						mViewPager.setCurrentItem(0);
					}
				});
		mbtnDSSWForm.setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						mViewPager.setCurrentItem(1);
					}
				});
		mbtnDWForm.setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						mViewPager.setCurrentItem(2);
					}
				});
		mbtnWSWForm.setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						mViewPager.setCurrentItem(3);
					}
				});
		mbtnHYSWForm.setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						mViewPager.setCurrentItem(4);
					}
				});
	}


}
